package com.ty.bigevent.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ty.bigevent.model.dto.CategoryUpdateRequest;
import com.ty.bigevent.model.entry.Category;
import com.ty.bigevent.model.vo.CategoryVO;
import com.ty.bigevent.service.CategoryService;
import com.ty.bigevent.mapper.CategoryMapper;
import com.ty.bigevent.utils.ThreadLocalUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* @author ong char
* @description 针对表【category】的数据库操作Service实现
* @createDate 2025-09-27 01:05:27
*/
@Service
@AllArgsConstructor
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{

    private final CategoryMapper categoryMapper ;
    @Override
    public void addCategory(String categoryName, String categoryAlias) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        Category category = new Category();
        category.setCategory_name(categoryName);
        category.setCategory_alias(categoryAlias);
        category.setCreate_user(userId);
        categoryMapper.addCategory(category);
    }

    @Override
    public List<CategoryVO> listCategory() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        return categoryMapper.listCategory(userId);
    }

    @Override
    public CategoryVO getCategoryById(Integer id) {
        return categoryMapper.getCategoryById(id);
    }

    @Override
    public void updateCategory(CategoryUpdateRequest params) {
        Category category = new Category();
        category.setId(params.getId());  // 设置ID，这是关键！
        category.setCategory_name(params.getCategoryName());
        category.setCategory_alias(params.getCategoryAlias());
        categoryMapper.updateCategory(category);
    }

    @Override
    public void deleteCategoryById(Integer id) {
        categoryMapper.deleteCategoryById(id);
    }
}




